package top.someapp.dxf2dsvg.entity;

import top.someapp.dxf2dsvg.base.Point;
import top.someapp.dxf2dsvg.base.Size;
import top.someapp.dxf2dsvg.dxf.Item;
import top.someapp.dxf2dsvg.kits.Numbers;

import javax.annotation.Nonnull;

/**
 * 圆
 *
 * @author zwz
 * Created on 2020-04-19
 * @see <a href="http://help.autodesk.com/view/OARX/2018/CHS/?guid=GUID-8663262B-222C-414D-B133-4A8506A27C18">
 * CIRCLE (DXF)</a>
 */
public class Circle extends EntityBase {
    private Point center;
    private Size radius;
    private boolean start;

    public Circle() {
        center = new Point();
        radius = new Size(1);
    }

    public Point getCenter() {
        return center;
    }

    public Circle setCenter(@Nonnull Point center) {
        this.center = center;
        return this;
    }

    public Size getRadius() {
        return radius;
    }

    public Circle setRadius(@Nonnull Size radius) {
        this.radius = radius;
        return this;
    }

    @Override
    public String type() {
        return "CIRCLE";
    }

    @Override
    public void setup(@Nonnull Item item) {
//        System.out.println("item in CIRCLE: " + item);
        if (!start && item.code == 100 && item.value.equals("AcDbCircle")) {
            start = true;
            return;
        }
        if (start) {
            switch (item.code) {
                case 10:
                    center.setX(Numbers.floatValue(item.value));
                    break;
                case 20:
                    center.setY(Numbers.floatValue(item.value));
                    break;
                case 30:
                    center.setZ(Numbers.floatValue(item.value));
                    break;
                case 40:
                    radius.setValue(Numbers.floatValue(item.value));
                    break;
            }
        }
    }

    @Override
    public String toString() {
        return "Circle{" +
                "center=" + center +
                ", radius=" + radius +
                '}';
    }
}
